#include "stdafx.h"
#include <string.h>
#include "ado/DbMysql.h"
#include "ado/Inserts.h"
#include "standard/nstring.h"
//#include "ado/fun_sets.h"
Inserts *Inserts::_init = NULL;

Inserts* Inserts::init(void *db)
{
    _init = new Inserts(db);
	return _init; 
}

Inserts::Inserts(void *db)
{
    m_db = (tDataBase*) db; 
    std::string classname = m_db->classname;
    
    if (!(m_db->database).empty()) {
        m_dbname = m_db->database;
    }
    
    this->m_classname   = tolower_str(classname);

		//GetFunInstance("tolower_str",this->m_classname,classname);
}


Inserts::~Inserts()
{
    m_db->database.clear();
    m_db->classname.clear();
}

Inserts *Inserts::insertp(std::map<std::string, std::string> setstr)
{
    this->m_setstr      = setstr;
  //  this->insertparam(this->m_setstr, this->m_classname);    
    return this;
}

int Inserts::create()
{
    std::string que;
     this->m_classname = tolower_str(this->m_classname);
        //GetFunInstance("tolower_str",this->m_classname,  this->m_classname );
    que = "Insert into " + m_dbname + "."  
                + m_prefix + this->m_classname + " (" 
                + this->getColumnOfStr(this->m_classname, this->m_setstr)
                + ") values (" 
                + this->getInsert() + ")" ;
    return DbMysql::instance()->execute(que.c_str())->insert_id();
}


